package com.agile4j.oss.server;

import com.agile4j.oss.adapter.DeleteError;
import com.agile4j.oss.adapter.OssClientAdapter;
import com.agile4j.oss.adapter.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @author  cthd
 * {@code @date}  2025/9/17 15:33
 * @version 1.0
 * Description: .class
 */
// OssTemplate.java
@Component
public class OssTemplate {

    @Autowired
    private OssClientAdapter adapter; // Spring 会根据条件注入 Minio 或 S3

    // 一比一代理所有方法
    public void existBucket(String name) {
        try {
            adapter.existBucket(name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public Boolean makeBucket(String bucketName) {
        return adapter.makeBucket(bucketName);
    }

    public Boolean removeBucket(String bucketName) {
        return adapter.removeBucket(bucketName);
    }

    public String download(String url, String path) {
        return adapter.download(url, path);
    }

    public InputStream download(String url) {
        return adapter.download(url);
    }

    public byte[] downloadByte(String url) {
        return adapter.downloadByte(url);
    }

    public ResponseEntity<byte[]> downloadByUrl(String url) {
        return adapter.downloadByUrl(url);
    }

    public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) {
        return adapter.removeObjects(bucketName, objects);
    }

    public String delete(String module, String fileName) {
        return adapter.delete(module, fileName);
    }

    public Boolean checkFileIsExist(String bucketName, String objectName) {
        return adapter.checkFileIsExist(bucketName, objectName);
    }

    public Map<String, Object> copyObject(String sourcePath, String copyPath) throws RuntimeException {
        return adapter.copyObject(sourcePath, copyPath);
    }

    public Map<String, Object> upload(MultipartFile multipartFile, String path) {
        return adapter.upload(multipartFile, path);
    }

    public Map<String, Object> upload(FileInputStream inputStream, String path, String fileName) {
        return adapter.upload(inputStream, path, fileName);
    }

    public List<Map<String, Object>> listObjects(String bucketName) {
        return adapter.listObjects(bucketName);
    }

    public String getPreviewUrl(String pathUrl) {
        return adapter.getPreviewUrl(pathUrl);
    }

    public void removeObject(String module, String fileName) {
         adapter.removeObject(module,fileName);
    }

    public List<String> getBucketObjects(String bucketName) {
        return adapter.getBucketObjects(bucketName);
    }

    public void createBucket(String bucketName) {
        adapter.createBucket(bucketName);
    }

    public void putObject(String module, String path, String filePath) {
        adapter.putObject(module,path,filePath);
    }
}